#include <iostream>
#include "userview_impl.h"
#include "tools.h"
#include <getch.h>
using namespace std;

UserViewImpl::UserViewImpl()
{
    service = new UserServiceImpl;//创建读者功能实现对象
}

void UserViewImpl::Menu()
{
	while(1)
	{
		system("clear");
		cout << "*********欢迎来到用户系统*******" << endl;
		cout << "\e[33m        1、显示用户信息\e[0m" << endl;
		cout << "\e[33m        2、书籍查找\e[0m" << endl;
		cout << "\e[33m        3、书籍预约\e[0m" << endl;
		cout << "\e[33m        4、书籍推荐\e[0m" << endl;
		cout << "\e[33m        5、退出\e[0m" << endl;
		cout << "*********************************" << endl;
		char cmd = 0;
		while(1)
		{
			cout << "\e[34m请输入指令:\e[0m";
			cmd = getch();
			if(cmd >='1' && cmd <='5')
				break;
		}
		cout << cmd << endl;
		switch(cmd-'0')
		{
			case 1:Reader();break;
			case 2:Search();break;
			case 3:Order();break;
			case 4:Recommend();break;
			case 5:return;
			
		}
 	}
}
//读者信息抄查
void UserViewImpl::Reader()
{
	int id;
	cout << "\e[34m请输入要查询用户的ID号：\e[0m" << endl;
	cin >> id;
    service->ReaderSearch(id);//调用读者信息查找函数
	anykey_continue();
}
//模糊搜索书籍
void UserViewImpl::Search()
{
	char name[40];
	cout << "\e[34m请输入要查询书籍相关名称：\e[0m" << endl;
	cin >> name;
    service->BookSearch(name);//调用书籍搜索函数
	anykey_continue();
}
//预约书籍
void UserViewImpl::Order()
{
	int r_id;
	int b_id;
	cout << "\e[34m请输入预约用户ID号：\e[0m" << endl;
	cin >> r_id;
	cout << "\e[34m请输入要预约书籍ID号：\e[0m" << endl;
	cin >> b_id;
	if(service->BookOrder(r_id,b_id))
	{
		cout << "\e[36m预约成功！！\e[0m" << endl;
	}
	else
	{
		cout << "\e[31m预约失败！！\e[0m" << endl;
	}
	anykey_continue();
}
void UserViewImpl::Recommend()
{
    service->Recommend();//调用推荐函数
    
}
UserViewImpl::~UserViewImpl()
{
	delete service;
}
